﻿@page "/Admin/ExLogs"
@attribute [Authorize]
@attribute [TabItemOption(Text ="异常日志",Icon ="fa fa-th")]
@inherits BasePage
@inject ISysExLogService SysExLogService

<div class="overflow-hidden h-100">
    <Table TItem="ExLogOutput"
            @ref = "@_table"
            IsPagination="true"
            IsStriped="true"
            IsMultipleSelect="true"
            IsBordered="true"
            IsFixedHeader="true" 
            AllowResizing="true"
            ShowLoading="true"
            ShowColumnList="true"
            ShowCardView="true"
            ShowToolbar="true"
            ShowDefaultButtons="false"
            ShowSearch="true"
            ShowEmpty="true" 
            SearchModel="@_search" 
            SearchMode="SearchMode.Top"
            PageItemsSource="@(new int[] { 15, 50 })"
            OnQueryAsync="@OnQueryAsync">
        <TableColumns>
            <TableColumn @bind-Field="@context.Account" Width="120" />
            <TableColumn @bind-Field="@context.ExceptionTime" Width="180" FormatString="yyyy-MM-dd HH:mm:ss"/>
            <TableColumn @bind-Field="@context.ExceptionName" TextEllipsis="true" />
        </TableColumns>
        <DetailRowTemplate>
            <div class="row g-3">
                <div class="col-12">发生账户：@context.Account</div>
                <div class="col-12">异常时间：@context.ExceptionTime</div>
                <div class="col-12">异常名称：@context.ExceptionName</div>
                <div class="col-12">异常类名：@context.ClassName</div>
                <div class="col-12">方法名称：@context.MethodName</div>
                <div class="col-12">异常信息：@context.ExceptionMsg</div>
            </div>
        </DetailRowTemplate>
        <TableToolbarTemplate>
            <TableToolbarButton TItem="ExLogOutput" Text="清空日志" IsAsync/>
        </TableToolbarTemplate>
        <SearchTemplate>
            <GroupBox Title="搜索条件">
                <div class="row g-3 form-inline">
                    <div class="col-4">
                        <BootstrapInput @bind-Value="@context.Name" ShowLabel="true"/>
                    </div>
                </div>
            </GroupBox>
        </SearchTemplate>
    </Table>
</div>

@code{
    private Table<ExLogOutput>? _table;
    private ExLogOutput _search = new();

    private Task<QueryData<ExLogOutput>> OnQueryAsync(QueryPageOptions options)
        => SysExLogService.PageAsync(_search.Adapt<ExLogPageInput>(options));
}

